package com.peanut.controller;

import com.peanut.common.Result;
import com.peanut.domain.vo.TabItemVO;
import com.peanut.service.TabItemService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("itemController")
public class ItemController {

    @Resource
    private TabItemService itemService;

    /**
     * 根据id查询商品
     * @param itemId : 商品ID
     * @return
     */
    @PostMapping("getItemByID")
    public Result getItemByID(Long itemId){
        try {
            TabItemVO item = itemService.getItemByID(itemId);
            return Result.OK().setData(item);
        }catch (Exception e){
            e.printStackTrace();
            return Result.ERROR();
        }
    }

    @PostMapping("getItemContry")
    public Result getItemContry(Integer itemContry){
        try {
            List<TabItemVO> list = itemService.getItemContry(itemContry);
            return Result.OK().setData(list);
        }catch (Exception e){
            e.printStackTrace();
            return Result.ERROR();
        }
    }

}
